import $http from "@/common/utils/http.ts"
import type { SearchParams, List, GoodsItem } from "../types/goods.d.ts"

interface Result<T> {
    code: number,
    data: T,
    message: string
}

export const goodsService = {
    /**  查询 */
    async getGoodesService(params: SearchParams) {
        const url = `/api/goods/getGoods`

        return await $http.get(url, params) as Result<List<GoodsItem>>
    },

    /**  删除 */
    async deleteGoodsService(params: { productId: string | number }) {
        const url = `/api/goods/deleteGoods`

        return await $http.del(url, params) as Result<number>
    },

    /**  增加 */
    async createGoodsService(params:GoodsItem){
        const url = `/api/goods/createGoods`
        return await $http.post(url, params) as Result<number>
    },

    /**  更新 */
    async updateGoodsService(params:GoodsItem){
        const url = `/api/goods/updateGoods`
        
        return await $http.put(url, params) as Result<number>
    }
}